import api from '@/api/index.js'
import { getToken, setToken, removeToken } from '@/utils/auth.js'


export default {
	namespaced: true,   
    state: {
        isLogin: false,
        app: {
            platform: ''
        },
		token: getToken()
    },
    mutations: {
        SET_IS_LOGIN(state, b) {
            state.isLogin = b
        },
        SET_APP_PLATFORM(state, s) {
            state.app.platform = s
        },
		SET_TOKEN: (state, token) => {
		    state.token = token
		}
    },
    actions: {
        login({dispatch,commit,state}){
			return new Promise((resolve, reject) => {
			    uni.login({
			        provider: 'weixin',
			        success: res => {
						api.home.login(res.code).then(resp=>{
							if(resp.ok){
								setToken(resp.token)
								console.log('获得 token：' + resp.token)
							}else{
								console.log('home/login 接口异常')
							}
							
						});
			     //        uni.getUserInfo({
			     //            provider: 'weixin',
			     //            withCredentials: true,
			     //            lang: 'zh_CN',
			     //            success: e => {
								// console.log(res)
			                    
			     //            }
			     //        })
			        }
			    })
			})
		}
    }
}